package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbItemMapper;
import com.dongdongshop.pojo.TbItem;
import com.dongdongshop.pojo.TbItemExample;
import com.dongdongshop.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private TbItemMapper tbItemMapper;

    @Override
    public List<TbItem> selectItemListByGoodsId(Long goodsId) {
        TbItemExample tbItemExample = new TbItemExample();
        TbItemExample.Criteria criteria = tbItemExample.createCriteria();
        //状态为正常的1
        criteria.andStatusEqualTo("1");
        //剩余库存大于1
        criteria.andStockCountGreaterThan(0);
        //传入的商品id
        criteria.andGoodsIdEqualTo(goodsId);
        tbItemExample.setOrderByClause("is_default desc");
        return tbItemMapper.selectByExample(tbItemExample);
    }

    @Override
    public TbItem selectById(Long itemId) {
        TbItem tbItem = tbItemMapper.selectByPrimaryKey(itemId);
        return tbItem;
    }
}
